package pyf;

/**
 * 模仿线程静态代理
 * 场景：找商家代理购买手机
 *
 * you只关心你自己得事，比如买手机，但是各种原因买不到手机，所以需要代理商代买
 * you和shop都需要实现buy接口
 */
public class StaticProxy {

    public static void  main(String[] args) {
        You you = new You();
        new Shop(you).buyPhone();


    }

     static class You implements Buy {

        @Override
        public void buyPhone() {
            System.out.println("我非常想要这部手机");
        }
    }

    static class Shop implements Buy {

         private Buy target;

        public Shop(Buy target) {
            this.target = target;
        }

        void before() {
            System.out.println("收取定价，下单");
        }

        @Override
        public void buyPhone() {
            before();
            System.out.println("商家经过一系列操作购买到了手机");
            after();
        }

        void after() {
            System.out.println("收取尾款交货");
        }
    }

    /**
     * 购买行为
     */
    interface Buy {
        void buyPhone();
    }


}
